package com.bases {
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	/**
	 *文字按钮
	 * @author Administrator
	 *
	 */
	public class LableButton extends TUIComponent {
		private var lblText:TLable; //文本文字
		private var fontSize:int; //字体大小
		private var oldColor:uint; //原始文本颜色
		private var overColor:uint; //鼠标划过去的颜色

		public function LableButton(text:String, size:int = 12, color:uint = 0x00ff00, overColor:uint = 0xff0000){
			super();
			this.lblText = new TLable();
			this.lblText.text = text;
			this.lblText.setFontSize(size, color);
			this.fontSize = size;
			this.oldColor = color;
			this.overColor = overColor;
			this.addChild(lblText);
			this.lblText.adateLabel();
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.useHandCursor = true;
			this.buttonMode = true;
		}

		/**
		 * 设置文本的值
		 * @param value
		 *
		 */
		public function set text(value:String):void {
			this.lblText.text = value;
		}

		/**
		 *设置此对象是否接收鼠标交互
		 * @param value
		 *
		 */
		public function set enabled(value:Boolean):void {
			this.mouseEnabled = value;
			if (value){
				this.lblText.setFontSize(this.fontSize, oldColor);
				this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			} else {
				this.lblText.setFontSize(this.fontSize, 0x434343);
				this.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
				this.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			}
		}

		/**
		 * 获取文本的值
		 * @return
		 *
		 */
		public function get text():String {
			return this.lblText.text;
		}

		/**
		 * 设置label的大小
		 * @param w 宽度
		 * @param h 高度
		 *
		 */
		override public function setSize(w:Number, h:Number):void {
			this.lblText.wordWrap = true;
			this.lblText.setSize(w, h);
		}

		private function onMouseOver(event:MouseEvent):void { /*鼠标划过去*/
			this.lblText.setFontSize(this.fontSize, overColor);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}

		private function onMouseOut(event:MouseEvent):void { /*鼠标划走*/
			this.lblText.setFontSize(this.fontSize, oldColor);
			this.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
	}
}